<script type="text/javascript">
    window.onload = function () {

        let arr;
        let newArr;

        console.log('[...new Set(arr)]方法去重***start***');
        arr = [1, 2, 1, 2, 5, 5];
        console.log(arr);
        newArr = [...new Set(arr)];
        console.log(newArr);
        console.log('***end***');

        console.log('filter方法去重***start***');
        arr = ['a', 'b', 'ab', 'ab', 'a', 'b'];
        console.log(arr);
        newArr = arr.filter((x, index, self) => self.indexOf(x) === index)
        console.log(newArr);
        console.log('***end***');

        console.log('8.数组对象去重***start***');
        let person = [{
                id: 0,
                name: "小明"
            },
            {
                id: 1,
                name: "小张"
            },
            {
                id: 2,
                name: "小张"
            },
            {
                id: 3,
                name: "小明"
            },
            {
                id: 4,
                name: "小孙"
            },
            {
                id: 5,
                name: "小孙"
            }
        ];
        console.log(person);
        let obj = {};
        let peon = person.reduce((cur, next) => {
            obj[next.name] ? "" : obj[next.name] = true && cur.push(next);
            return cur;
        }, []) //设置cur默认类型为数组，并且初始值为空的数组
        console.log(peon);
        console.log('***end***');

    }
</script>